<?php 
/* P3(c)

******************************************************************************
                                                                                      
                         __                                                        
                        /__)                                                       
                       /__        P3 - moving Technologie            
                        __)                                                          
                        __)                                                          
                                                                                        
                                                                                        
       Copyright 2009 by p3.co.at                                                                                 
                                                                                        
       visit www.p3.co.at to get more Informations 
       about Teriko - Betriebsdatenerfassung                                                                                 
       - it's not allowed to change this scripts
       - it's not allowed to remove this copyright-tag

       -- you can download the complete license   
          under http://www.teriko.org

 (c) by Patrik Pfaffenbauer and P3 (http://www.p3.co.at)

 | Programname: P3.Teriko
 | Authtor: P3.Verein
 | Coder: Patrik Pfaffenbauer
 | Version: 0.1

 | Change Index
 |_____________________________________________
 |                                             |
 |4.3.2010 Erstellung | Patrik Pfaffenbauer    |
 |_____________________________________________|

******************************************************************************

P3(c) */

class Department extends Base2
{
		
	public function Department()
	{
		$this->title = $GLOBALS['lang']->GetLanguage("Department", "title");
		$this->toolbar = true;
		$this->moduleID = 160;
		$this->permission = GetPermission($this->moduleID);
		
		$this->toolbarClass = "icon-48-customer";
		
		if(PermissionCount($this->permission) == 0)
		{
			$this->allowed = false;
		}

	}
	
	public function AnalysPost()
	{
		include("./_tables.php");
		
		if($_POST['action'] == "save")
		{	
			$_POST['validTo'] = ConvertDate($_POST['validTo'], ".");
			$GLOBALS['db']->SaveObject($tbldepartment);
			$this->Paint();
		}
		else if($_POST['action'] == "update")
		{
			if($_POST['id'] == "")
				return;
				
			$_POST['validTo'] = ConvertDate($_POST['validTo'], ".");
			$GLOBALS['db']->UpdateObject($tbldepartment);
			$this->Paint();
		}
		else if($_POST['action'] == 'add' || $_POST['action'] == "copy")
		{
			$this->Add();
		}
		else
		{
			$this->Paint();
		}
	}
	
	public function Add()
	{
		include("./_tables.php");
		$smarty = GetSmarty();
		$smarty->assign("editPanel", true);
	 	
		if($this->error)
		{
			$smarty->assign("error",  $this->errorText);
		}
		
		if($_POST['action'] == "add" && !$this->error)
		{
			foreach($_POST as $key => $value)
			{	
				$_POST[$key] = "";
			}
		}

		$smarty->assign("anrede", simplexml_load_file('./lang/de-de.xml')->{"Teriko-Modules"}->{"Anrede"});
		$smarty->assign("name", $_POST['name']);
		$smarty->assign("validTo", $_POST['validTo']);
		
		//Grunddaten
		$smarty->assign("defaultWorkModel", $GLOBALS['db']->GetMysqlArray($GLOBALS['db']->Query("SELECT * FROM ".$tblworktimemodel)));
		$smarty->assign("workModelVal", $_POST['workModel']);
		
		$smarty->assign("defaultHolidayModel", $GLOBALS['db']->GetMysqlArray($GLOBALS['db']->Query("SELECT * FROM ".$tblholidaymodel)));
		$smarty->assign("holidayModelVal", $_POST['holidayModel']);
		
		$smarty->assign("layerPlanner", $_POST['layerPlanner']);
		$smarty->assign("capacityPlanning", $_POST['capacityPlanning']);
		
		//Adresse
		$smarty->assign("addressName1", $_POST['addressname1']);
		$smarty->assign("addressName2", $_POST['addressname2']);
		$smarty->assign("street", $_POST['street']);
		$smarty->assign("zipcode", $_POST['zipcode']);
		$smarty->assign("city", $_POST['city']);
		$smarty->assign("country", $_POST['country']);
		$smarty->assign("region", $_POST['region']);
		$smarty->assign("telprefix", $_POST['telprefix']);
		$smarty->assign("telephone", $_POST['telephone']);
		$smarty->assign("telefax", $_POST['telefax']);
		$smarty->assign("email", $_POST['email']);
		$smarty->assign("homepage", $_POST['homepage']);
		
		//Ansprechpartner
		$smarty->assign("anredeVal", $_POST['anrede']);
		$smarty->assign("title", $_POST['title']);
		$smarty->assign("firstname", $_POST['firstname']);
		$smarty->assign("lastname", $_POST['lastname']);
		$smarty->assign("ctelprefix", $_POST['ctelprefix']);
		$smarty->assign("ctelephone", $_POST['ctelephone']);
		$smarty->assign("ctelefax", $_POST['ctelefax']);
		$smarty->assign("cemail", $_POST['cemail']);
		$smarty->assign("chomepage", $_POST['chomepage']);
		
		//Bemerkung
		$smarty->assign("note", $_POST['note']);
		$smarty->assign("tabIndex", 0); 
		$smarty->assign("type", "save"); 
		
		$smarty->assign('hiddenFields', array( 
					array('name' => 'action','value' => "save"),
                    array('name' => 'option','value' => 'department')));
		
       	$smarty->display('base/department.tpl');  
	}	
	public function Paint()
	{
		
		include("./_tables.php");
		$this->dataTable = $tbldepartment;
		$this->selectSql = "SELECT *,DATE_FORMAT(validTo,'%d.%m.%Y') as validTo2 FROM ".$tbldepartment." ";
		$this->PaintEditPanel();
		
		$this->smarty->assign("editPanel", true);
	 	
		
		if($this->error)
		{
			$this->smarty->assign("error",  $this->errorText);
		}
		
		if($this->hasData)
		{
			$this->smarty->assign("anrede", simplexml_load_file('./lang/de-de.xml')->{"Teriko-Modules"}->{"Anrede"});
			$this->smarty->assign("name", $this->data->name);
			$this->smarty->assign("validTo", $this->data->validTo2);
			
			//Grunddaten
			$this->smarty->assign("defaultWorkModel", $GLOBALS['db']->GetMysqlArray($GLOBALS['db']->Query("SELECT * FROM ".$tblworktimemodel)));
			$this->smarty->assign("workModelVal", $this->data->workModel);
			
			$this->smarty->assign("defaultHolidayModel", $GLOBALS['db']->GetMysqlArray($GLOBALS['db']->Query("SELECT * FROM ".$tblholidaymodel)));
			$this->smarty->assign("holidayModelVal", $this->data->holidayModel);
			
			$this->smarty->assign("layerPlanner", $this->data->layerPlanner);
			$this->smarty->assign("capacityPlanning", $this->data->capacityPlanning);
			
			//Adresse
			$this->smarty->assign("addressName1", $this->data->addressname1);
			$this->smarty->assign("addressName2", $this->data->addressname2);
			$this->smarty->assign("street", $this->data->street);
			$this->smarty->assign("zipcode", $this->data->zipcode);
			$this->smarty->assign("city", $this->data->city);
			$this->smarty->assign("country", $this->data->country);
			$this->smarty->assign("region", $this->data->region);
			$this->smarty->assign("telprefix", $this->data->telprefix);
			$this->smarty->assign("telephone", $this->data->telephone);
			$this->smarty->assign("telefax", $this->data->telefax);
			$this->smarty->assign("email", $this->data->email);
			$this->smarty->assign("homepage", $this->data->homepage);
			
			//Ansprechpartner
			$this->smarty->assign("anredeVal", $this->data->anrede);
			$this->smarty->assign("title", $this->data->title);
			$this->smarty->assign("firstname", $this->data->firstname);
			$this->smarty->assign("lastname", $this->data->lastname);
			$this->smarty->assign("ctelprefix", $this->data->ctelprefix);
			$this->smarty->assign("ctelephone", $this->data->ctelephone);
			$this->smarty->assign("ctelefax", $this->data->ctelefax);
			$this->smarty->assign("cemail", $this->data->cemail);
			$this->smarty->assign("chomepage", $this->data->chomepage);
			
			//Bemerkung
			$this->smarty->assign("note", $this->data->note);
		}
		
		$this->smarty->assign("type", "update");
		
		$this->smarty->assign('hiddenFields', array( 
					array('name' => 'action','value' => "update"),
                    array('name' => 'option','value' => 'department'),
                    array('name' => 'id','value' => $this->data->id),
                    array('name' => 'search','value' => ($_POST ['search'] != "") ? $_POST['search'] : $this->search)));

        $this->smarty->assign("tabIndex", ($_POST['hiddenTabIndex'] == "") ? 0 : $_POST['hiddenTabIndex']);
        $this->smarty->display('base/department.tpl');
	}
	
	public function Toolbar()
	{
		if($this->allowed)
		{
			PaintDefaultToolbar($this);
		}
	}

	public function AddCSS()
	{
			
	}
	public function AddJS()
	{
		
	}
}

?>